package fischl.web;

import fi.iki.elonen.NanoHTTPD;
import fischl.Global;
import fischl.model.Room;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static fi.iki.elonen.NanoHTTPD.*;

public class RoomHandler implements RouteHandler {
  @Override
  public NanoHTTPD.Response handle(NanoHTTPD.IHTTPSession session) {
    if (!"/room".equals(session.getUri())) return null;
    List<Room> all = Room.loadAll();
    Map<String, Object> model = new HashMap<>();
    model.put("upList", Global.gson().toJson(all));
    String result = TemplateEngine.render("up.ftlh", model);
    return newFixedLengthResponse(Response.Status.OK, "text/html", result);
  }
}
